package cn.maszy.service.impl.projectmanagement;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.DateUtils;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.projectmanagement.B_T_Ufp_TaskHandoutMapper;
import cn.maszy.dao.projectmanagement.B_T_Ufp_TaskManagerMapper;
import cn.maszy.dao.systemsetting.B_T_Sys_OperatingLogsMapper;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskHandout;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskManager;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskManagerExample;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskManagerExample.Criteria;
import cn.maszy.model.systemsetting.B_T_Sys_OperatingLogs;
import cn.maszy.service.projectmanagement.B_T_Ufp_TaskManagerService;
@Service
public class B_T_Ufp_TaskManagerServiceImpl implements B_T_Ufp_TaskManagerService {

	@Autowired
	private B_T_Ufp_TaskManagerMapper b_T_Ufp_TaskManagerMapper; 
	@Autowired
	private B_T_Ufp_TaskHandoutMapper b_T_Ufp_TaskHandoutMapper;
	@Autowired
	private B_T_Sys_OperatingLogsMapper b_T_Sys_OperatingLogsMapper;
	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_AdminService#update(cn.maszy.model.investment.B_T_Ufp_Admin, cn.maszy.model.investment.B_T_Ufp_AdminExample)
	 */
	public int update(B_T_Ufp_TaskManager b_T_Ufp_TaskManager,String flag,double taskActualTimeSpent,String taskSpeed,String remark) {
		// TODO Auto-generated method stub
		 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期时间
		B_T_Ufp_TaskHandout b_T_Ufp_TaskHandout = new B_T_Ufp_TaskHandout();
		B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs= new B_T_Sys_OperatingLogs();
		 if("add".equals(flag)){
			// b_T_Ufp_TaskManager.setTaskid(UUID.randomUUID().toString());
			 b_T_Ufp_TaskManager.setIsDelete(0);
			 b_T_Ufp_TaskManager.setCreateTime(new Date());
			 b_T_Ufp_TaskManager.setCreateUser(SessionFactory.getSessionUserRealNam());
			 int i= b_T_Ufp_TaskManagerMapper.insert(b_T_Ufp_TaskManager);
			//状态  type_status 1.关闭  2.删除  3.更新指派  4.导出  5.报工  6.接受 7.转派
					b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
					b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
					b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
					b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
					b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"创建了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,并指派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
					b_T_Ufp_TaskHandout.setTypeStatus("1");
					b_T_Ufp_TaskHandout.setRemark("创建任务");
					b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
					b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
					b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setIsDelete(0);
					b_T_Ufp_TaskHandout.setCreateTime(new Date());
					b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setUpdateTime(new Date());
					b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
					
					/**
					 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
					 */
					b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
					b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
					b_T_Sys_OperatingLogs.setModuleId("");
					b_T_Sys_OperatingLogs.setModuleName("任务管理");
					b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"创建了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,并指派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
					b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
					b_T_Sys_OperatingLogs.setType(2);
					b_T_Sys_OperatingLogs.setRemark("创建任务");
					b_T_Sys_OperatingLogs.setIsDelete(0);
					b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setCreateTime(new Date());
					b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setUpdateTime(new Date());
					b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
				return i;
		 }
		 else
		 {
			 if("1".equals(flag)){
				 b_T_Ufp_TaskManager.setTaskActualStartTime(df.format(new Date()));// new Date()
			 }
			 if("2".equals(flag)){
				 if("100%".equals(b_T_Ufp_TaskManager.getTaskSpeed())){
					 b_T_Ufp_TaskManager.setTaskActualEndTime(df.format(new Date()));// new Date()
				 }
			 }
			 b_T_Ufp_TaskManager.setUpdateTime(new Date());
			 b_T_Ufp_TaskManager.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 int i= b_T_Ufp_TaskManagerMapper.updateByPrimaryKeySelective(b_T_Ufp_TaskManager);
			//flag= 1 接受  2 报工 3 转派
				if("1".equals(flag)){
					b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
					b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
					b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
					b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
					b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
					b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setRemark("接受任务");
					//设置5个基本字段
					b_T_Ufp_TaskHandout.setIsDelete(0);
					b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
					b_T_Ufp_TaskHandout.setCreateTime(new Date());
					b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setUpdateTime(new Date());
					b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"接受了"+b_T_Ufp_TaskManager.getSentPeople()+"指派的["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务");
					b_T_Ufp_TaskHandout.setTypeStatus("6");
					b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
					/**
					 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
					 */
					b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
					b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
					b_T_Sys_OperatingLogs.setModuleId("");
					b_T_Sys_OperatingLogs.setModuleName("我的任务");
					b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"接受了"+b_T_Ufp_TaskManager.getSentPeople()+"指派的["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务");
					b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
					b_T_Sys_OperatingLogs.setType(2);
					b_T_Sys_OperatingLogs.setRemark("接受任务");
					b_T_Sys_OperatingLogs.setIsDelete(0);
					b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setCreateTime(new Date());
					b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setUpdateTime(new Date());
					b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
				}else if("2".equals(flag)){
					b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
					b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
					b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
					b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
					b_T_Ufp_TaskHandout.setTaskSpeed(b_T_Ufp_TaskManager.getTaskSpeed());
					b_T_Ufp_TaskHandout.setSumTime(b_T_Ufp_TaskManager.getTaskActualTimeSpent());
					b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
					b_T_Ufp_TaskHandout.setFrstTime(taskActualTimeSpent);
					b_T_Ufp_TaskHandout.setFishSpeed(taskSpeed);
					b_T_Ufp_TaskHandout.setRemark(remark);
					b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
					b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
					//设置5个基本字段
					b_T_Ufp_TaskHandout.setIsDelete(0);
					b_T_Ufp_TaskHandout.setCreateTime(new Date());
					b_T_Ufp_TaskHandout.setWorkHours(DateUtils.now());
					b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setUpdateTime(new Date());
					b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
					if(taskSpeed == null){
						b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"用时"+b_T_Ufp_TaskManager.getTaskActualTimeSpent()+"小时将["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,进度从0%更新至"+b_T_Ufp_TaskManager.getTaskSpeed());
					}else{
						b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"用时"+b_T_Ufp_TaskManager.getTaskActualTimeSpent()+"小时将["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,进度从"+taskSpeed+"更新至"+b_T_Ufp_TaskManager.getTaskSpeed());
					}
					b_T_Ufp_TaskHandout.setTypeStatus("5");
					b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
					/**
					 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
					 */
					b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
					b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
					b_T_Sys_OperatingLogs.setModuleId("");
					b_T_Sys_OperatingLogs.setModuleName("我的任务");
					if(taskSpeed == null){
						b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"用时"+b_T_Ufp_TaskManager.getTaskActualTimeSpent()+"小时将["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,进度从0%更新至"+b_T_Ufp_TaskManager.getTaskSpeed());
					}else{
						b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"用时"+b_T_Ufp_TaskManager.getTaskActualTimeSpent()+"小时将["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,进度从"+taskSpeed+"更新至"+b_T_Ufp_TaskManager.getTaskSpeed());
					}
					b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
					b_T_Sys_OperatingLogs.setType(2);
					b_T_Sys_OperatingLogs.setRemark(remark);
					b_T_Sys_OperatingLogs.setIsDelete(0);
					b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setCreateTime(new Date());
					b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setUpdateTime(new Date());
					b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
				}else if("3".equals(flag)){
				//鎻掑叆璁板綍琛�
				b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
				b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
				b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
				b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
				b_T_Ufp_TaskHandout.setRemark(remark);
				b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
				b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"更新了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,转派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
				b_T_Ufp_TaskHandout.setTypeStatus("7");
				//设置5个基本字段
				b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
				b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandout.setIsDelete(0);
				b_T_Ufp_TaskHandout.setCreateTime(new Date());
				b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandout.setUpdateTime(new Date());
				b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
				
				/**
				 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
				 */
				b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
				b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
				b_T_Sys_OperatingLogs.setModuleId("");
				b_T_Sys_OperatingLogs.setModuleName("我的任务");
				b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"更新了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,转派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
				b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
				b_T_Sys_OperatingLogs.setType(2);
				b_T_Sys_OperatingLogs.setRemark(remark);
				b_T_Sys_OperatingLogs.setIsDelete(0);
				b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setCreateTime(new Date());
				b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setUpdateTime(new Date());
				b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
				}else{
					//鎻掑叆璁板綍琛�
					b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
					b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
					b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
					b_T_Ufp_TaskHandout.setRemark(remark);
					b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
					//设置5个基本字段
					b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
					b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
					b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setIsDelete(0);
					b_T_Ufp_TaskHandout.setCreateTime(new Date());
					b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setUpdateTime(new Date());
					b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"更新了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,并且将任务指派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
					b_T_Ufp_TaskHandout.setTypeStatus("3");
					b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
					
					/**
					 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
					 */
					b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
					b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
					b_T_Sys_OperatingLogs.setModuleId("");
					b_T_Sys_OperatingLogs.setModuleName("任务管理");
					b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"更新了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务,并且将任务指派给"+b_T_Ufp_TaskManager.getAccusedPeople()+"负责");
					b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
					b_T_Sys_OperatingLogs.setType(2);
					b_T_Sys_OperatingLogs.setRemark(remark);
					b_T_Sys_OperatingLogs.setIsDelete(0);
					b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setCreateTime(new Date());
					b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
					b_T_Sys_OperatingLogs.setUpdateTime(new Date());
					b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
				}
				return i;
		 }
	}
	

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_AdminService#selectOne(java.lang.String)
	 */
	public B_T_Ufp_TaskManager selectOne(String staffId) {
		// TODO Auto-generated method stub
		B_T_Ufp_TaskManager record=b_T_Ufp_TaskManagerMapper.selectByPrimaryKey(staffId);
		if("".equals(staffId)){
			record = new B_T_Ufp_TaskManager();
		}
		return record;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_AdminService#delete(java.lang.String)
	 */
	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		
		B_T_Ufp_TaskManager b_T_Ufp_TaskManager= new B_T_Ufp_TaskManager();
		B_T_Ufp_TaskHandout b_T_Ufp_TaskHandout = new B_T_Ufp_TaskHandout();
		B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs= new B_T_Sys_OperatingLogs();
		B_T_Ufp_TaskManagerExample example = new B_T_Ufp_TaskManagerExample();
		for (String id : checkIds.split(", ")) {
			if(!id.equals("on")){
				example.or().andTaskidEqualTo(id);
				b_T_Ufp_TaskManager = b_T_Ufp_TaskManagerMapper.selectByPrimaryKey(id);
				b_T_Ufp_TaskManager.setIsDelete(1);
				b_T_Ufp_TaskManagerMapper.updateByPrimaryKeySelective(b_T_Ufp_TaskManager);
				//插入一条记录
				b_T_Ufp_TaskHandout.setTaskhandId(UUID.randomUUID().toString());
				b_T_Ufp_TaskHandout.setProjectId(b_T_Ufp_TaskManager.getProjectUuid());
				b_T_Ufp_TaskHandout.setTaskid(b_T_Ufp_TaskManager.getTaskid());
				b_T_Ufp_TaskHandout.setTaskName(b_T_Ufp_TaskManager.getTaskName());
				b_T_Ufp_TaskHandout.setUserId(SessionFactory.getSessionUserId());
				b_T_Ufp_TaskHandout.setUserName(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandout.setRemark("删除任务");
				b_T_Ufp_TaskHandout.setIsDelete(0);
				b_T_Ufp_TaskHandout.setAcceptedTime(DateUtils.nows());
				b_T_Ufp_TaskHandout.setCreateTime(new Date());
				b_T_Ufp_TaskHandout.setCreateUser(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandout.setUpdateTime(new Date());
				b_T_Ufp_TaskHandout.setUpdateUser(SessionFactory.getSessionUserRealNam());
				b_T_Ufp_TaskHandout.setHandzettelContent(SessionFactory.getSessionUserRealNam()+"删除了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务");
				b_T_Ufp_TaskHandout.setTypeStatus("2");
				b_T_Ufp_TaskHandoutMapper.insert(b_T_Ufp_TaskHandout);
				
				/**
				 * 操作记录和工作日志  type:1.正常操作记录 2.工作日志
				 */
				b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
				b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setTaskId(b_T_Ufp_TaskManager.getTaskid());
				b_T_Sys_OperatingLogs.setModuleId("");
				b_T_Sys_OperatingLogs.setModuleName("任务管理");
				b_T_Sys_OperatingLogs.setOperatingContent(SessionFactory.getSessionUserRealNam()+"删除了["+b_T_Ufp_TaskManager.getRespectiveProject()+"]项目下&lt;&lt;"+b_T_Ufp_TaskManager.getTaskName()+"&gt;&gt;任务");
				b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
				b_T_Sys_OperatingLogs.setType(2);
				b_T_Sys_OperatingLogs.setRemark("删除任务");
				b_T_Sys_OperatingLogs.setIsDelete(0);
				b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setCreateTime(new Date());
				b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
				b_T_Sys_OperatingLogs.setUpdateTime(new Date());
				b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
			}
		}
		return 1;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_AdminService#selectList(cn.maszy.model.investment.B_T_Ufp_Admin)
	 */
	public Pager<B_T_Ufp_TaskManager> selectList(B_T_Ufp_TaskManager b_T_Ufp_TaskManager,Pager<B_T_Ufp_TaskManager> pager,String flag) {
		// TODO Auto-generated method stub
		// 实例化exmple
		B_T_Ufp_TaskManagerExample example=new B_T_Ufp_TaskManagerExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsDeleteEqualTo(0);
			if(b_T_Ufp_TaskManager!=null){
				if(b_T_Ufp_TaskManager.getTaskName()!=null && !"".equals(b_T_Ufp_TaskManager.getTaskName())){
					criteria.andTaskNameLike("%"+b_T_Ufp_TaskManager.getTaskName()+"%");
				}
				if(b_T_Ufp_TaskManager.getRespectiveProject() != null && !"".equals(b_T_Ufp_TaskManager.getRespectiveProject())){
					criteria.andRespectiveProjectLike("%"+b_T_Ufp_TaskManager.getRespectiveProject()+"%");
				}
				if(b_T_Ufp_TaskManager.getAccusedPeople() != null && !"".equals(b_T_Ufp_TaskManager.getAccusedPeople())){
					criteria.andAccusedPeopleEqualTo(b_T_Ufp_TaskManager.getAccusedPeople());
				}
				if(b_T_Ufp_TaskManager.getSentPeople() != null && !"".equals(b_T_Ufp_TaskManager.getSentPeople())){
					criteria.andSentPeopleEqualTo(b_T_Ufp_TaskManager.getSentPeople());
				}
				
			}
			/**
			 * 查找当前任务的 UUID
			 * 任务追踪搜索及查询排序
			 * */
			if(!"".equals(flag) && flag != null){
				criteria.andProjectUuidEqualTo(flag);
				if("1".equals(b_T_Ufp_TaskManager.getTaskSpeed())){
					criteria.andTaskSpeedEqualTo("100%");
					example.or(criteria);
				}else if("2".equals(b_T_Ufp_TaskManager.getTaskSpeed())){
					example.or(criteria);
				}else{
					criteria.andTaskSpeedNotEqualTo("100%");
					if(b_T_Ufp_TaskManager.getTaskName()!=null && !"".equals(b_T_Ufp_TaskManager.getTaskName()) || b_T_Ufp_TaskManager.getRespectiveProject() != null && !"".equals(b_T_Ufp_TaskManager.getRespectiveProject()) || b_T_Ufp_TaskManager.getAccusedPeople() != null && !"".equals(b_T_Ufp_TaskManager.getAccusedPeople())){
						example.or().andTaskSpeedIsNull().andProjectUuidEqualTo(flag).andTaskNameLike("%"+b_T_Ufp_TaskManager.getTaskName()+"%").andRespectiveProjectLike("%"+b_T_Ufp_TaskManager.getRespectiveProject()+"%").andAccusedPeopleEqualTo(b_T_Ufp_TaskManager.getAccusedPeople());
					}else{
						example.or().andTaskSpeedIsNull().andProjectUuidEqualTo(flag);
					}
				}
			}else{
				/**
				 * 任务管理 未完成 及已完成搜索条件
				 * */
			if(b_T_Ufp_TaskManager != null){
			if(b_T_Ufp_TaskManager.getTaskName()!=null && !"".equals(b_T_Ufp_TaskManager.getTaskName()) || b_T_Ufp_TaskManager.getRespectiveProject() != null && !"".equals(b_T_Ufp_TaskManager.getRespectiveProject())){
				if("1".equals(b_T_Ufp_TaskManager.getTaskSpeed())){
					criteria.andTaskSpeedEqualTo("100%");
					example.or(criteria);
				}else{
					criteria.andTaskSpeedNotEqualTo("100%");
					if("".equals(b_T_Ufp_TaskManager.getAccusedPeople())){
						example.or().andTaskSpeedIsNull().andSentPeopleEqualTo(b_T_Ufp_TaskManager.getSentPeople()).andTaskNameLike("%"+b_T_Ufp_TaskManager.getTaskName()+"%").andRespectiveProjectLike("%"+b_T_Ufp_TaskManager.getRespectiveProject()+"%");
					}else{
						example.or().andTaskSpeedIsNull().andAccusedPeopleEqualTo(b_T_Ufp_TaskManager.getAccusedPeople()).andTaskNameLike("%"+b_T_Ufp_TaskManager.getTaskName()+"%").andRespectiveProjectLike("%"+b_T_Ufp_TaskManager.getRespectiveProject()+"%");
					}
				}
			}else{
				/**
				 * 任务管理已完成搜索
				 * */
				if("1".equals(b_T_Ufp_TaskManager.getTaskSpeed())){
					criteria.andTaskSpeedEqualTo("100%");
					example.or(criteria);
				}else{
					/**
					 *任务管理查询  及我的任务管理查询
					 * */
					criteria.andTaskSpeedNotEqualTo("100%");
					Criteria criteria2 = example.createCriteria();
					if("".equals(b_T_Ufp_TaskManager.getAccusedPeople()) || b_T_Ufp_TaskManager.getAccusedPeople() == null){
						criteria2.andSentPeopleEqualTo(b_T_Ufp_TaskManager.getSentPeople());
					}else{
						criteria2.andAccusedPeopleEqualTo(b_T_Ufp_TaskManager.getAccusedPeople());
					}
					criteria2.andIsDeleteEqualTo(0);
					criteria2.andTaskSpeedIsNull();
					example.or(criteria2);
				}
			}
			}
			}
		int totalCount=new B_T_Ufp_TaskManagerServiceImpl().count(example,b_T_Ufp_TaskManagerMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		
		//查询LIST
		List<B_T_Ufp_TaskManager>  list=b_T_Ufp_TaskManagerMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}


	public int count(B_T_Ufp_TaskManagerExample example,B_T_Ufp_TaskManagerMapper b_T_Ufp_TaskManagerMapper) {
		// TODO Auto-generated method stub
		return b_T_Ufp_TaskManagerMapper.countByExample(example);
	}
	 /* 待接收的任务 */
	public int selectCount(String username){
		B_T_Ufp_TaskManagerExample example=new B_T_Ufp_TaskManagerExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsDeleteEqualTo(0);
		criteria.andAccusedPeopleEqualTo(username);
		criteria.andTaskActualEndTimeIsNull();
		example.or(criteria);
		List<B_T_Ufp_TaskManager>  list = b_T_Ufp_TaskManagerMapper.selectByExample(example);
		return list.size();
	}
	 /* 正在进行中的任务 */
	public int queryCount(String username){
		B_T_Ufp_TaskManagerExample example=new B_T_Ufp_TaskManagerExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsDeleteEqualTo(0);
		criteria.andAccusedPeopleEqualTo(username);
		criteria.andTaskSpeedNotEqualTo("100%");
		example.or(criteria);
		List<B_T_Ufp_TaskManager>  list = b_T_Ufp_TaskManagerMapper.selectByExample(example);
		return list.size();
		
	}
}
